#include<bits/stdc++.h>
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using pii=std::pair<int,int>;
#define fst first
#define scd second
#define all(x) std::begin(x),std::end(x)
#define y0 y000000
#define y1 y111111
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define irep(i,s,t) for(int i=(s);i>=(t);i--)
template<typename T> bool chmax(T &x,T const &y){
    return x<y?x=y,true:false;
}
template<typename T> bool chmin(T &x,T const &y){
    return y<x?x=y,true:false;
}
using namespace std;
template<typename T=int>
T read(){
    T x=0,f=1;
    char c=getchar();
    while(!isdigit(c)){
        f=c=='-'?-1:1;
        c=getchar();
    }
    while(isdigit(c)){
        x=x*10+(c-'0');
        c=getchar();
    }
    return x*f;
}
const double eps=1e-10;
ll constexpr floor_div(ll,ll);
ll constexpr ceil_div(ll,ll);
ll constexpr floor_div(ll x,ll y){
    return y<0?ceil_div(-x,-y):(
        x<0?-ceil_div(-x,y):x/y
    );
}
ll constexpr ceil_div(ll x,ll y){
    return y<0?floor_div(-x,-y):(
        x<0?-floor_div(-x,y):(x+y-1)/y
    );
}
void work(){
    int n,m,L,V;
    n=read(),m=read(),L=read(),V=read();
    auto sqr=[](int x)->ll {
        return x*x;
    };
    vector<tuple<int,int,int>> cars;
    vector<int> ps;
    rep(i,0,n-1){
        int d,v,a;
        d=read(),v=read(),a=read();
        cars.emplace_back(d,v,a);
    }
    rep(i,0,m-1){
        int x=read();
        ps.push_back(x);
    }
    sort(all(ps));
    vector<pii> rg;
    rep(i,0,n-1){
        int d,v,a;
        tie(d,v,a)=cars[i];
        int l,r;
        if(a==0){
            if(v<=V) continue;
            l=d,r=L;
        }
        else if(a>0){
            l=max((ll)d,d+ceil_div(sqr(V)-sqr(v)+1,2*a));
            r=L;
        }
        else{
            l=d;
            r=min((ll)L,d+floor_div(sqr(v)-sqr(V)-1,-2*a));
        }
        // cout<<i<<' '<<l<<','<<r<<'\n';
        if(l>r+eps) continue;
        int x=lower_bound(all(ps),l)-ps.begin();
        int y=upper_bound(all(ps),r)-ps.begin()-1;
        if(x>y) continue;
        rg.emplace_back(x,y);
        // cout<<i<<' '<<x<<','<<y<<'\n';
    }
    cout<<rg.size()<<' ';
    priority_queue<int,vector<int>,greater<int>> re;
    vector<vector<pii>> rgs(m);
    for(auto [l,r]:rg){
        rgs[l].emplace_back(l,r);
    }
    int ans=0;
    rep(i,0,m-1){
        for(auto [l,r]:rgs[i]){
            re.push(r);
        }
        if(!re.empty()&&re.top()==i){
            ans++;
            while(!re.empty())re.pop();
        }
    }
    cout<<m-ans<<'\n';
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    int T=read();
    while(T--) work();
}